1 // Copyright (C) 2024 Rubén Beltrán del Río
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see https://map.tranquil.systems.
17 struct MapBlockers: View {
20 let vertexSize: CGSize
21 let blockers: [Blocker]
23 let cornerSize = CGSize(width: 2.0, height: 2.0)
26 ForEach(blockers, id: \.id) { vertex in
31 x: w(vertex.position.x) + 3 * vertexSize.width,
32 y: h(vertex.position.y) - vertexSize.height * 2 / 3),
33 size: CGSize(width: vertexSize.width / 2, height: vertexSize.height * 2)
34 ), cornerSize: cornerSize)
35 }.fill(Color.Map.blockerColor)
39 func h(_ dimension: CGFloat) -> CGFloat {
40 max(0.0, min(mapSize.height, dimension * mapSize.height / 100.0))
43 func w(_ dimension: CGFloat) -> CGFloat {
44 max(0.0, min(mapSize.width, dimension * mapSize.width / 100.0))
50 mapSize: CGSize(width: 400.0, height: 400.0), vertexSize: CGSize(width: 25.0, height: 25.0),
52 Blocker(id: 0, position: CGPoint(x: 50.0, y: 50.0)),
53 Blocker(id: 1, position: CGPoint(x: 10.0, y: 20.0)),